package br.ufpe.cin.rdfilter.util;

import java.util.List;

import br.ufpe.cin.rdfilter.model.Feedback;

public class Measure {

	private double precision;
	private double recall;
	private double f_measure;
	private int tp = 0;
	private int fp = 0;
	private int fn = 0;
	
	public void calculate(List<Feedback> f){
		tp=fp=fn=0;
		for(int i=0;i<f.size();i++){
			if(f.get(i).getType().equals("True Positive"))
				tp++;
			else if (f.get(i).getType().equals("False Positive"))
				fp++;
			else fn++;
		}
		
		if(tp==0 && fp ==0)
			precision=0.0;
		else precision = ((double) (tp)) / ((double) (tp + fp));
		
		if(tp==0 && fn==0)
			recall=0.0;
		else recall = ((double) (tp)) / ((double) (tp + fn));
		
		if(precision==0.0 || recall==0.0)
			f_measure=0.0;
		else f_measure = 2 * precision * recall / (precision + recall);
	}

	public double getPrecision() {
		return precision;
	}

	public void setPrecision(double precision) {
		this.precision = precision;
	}

	public double getRecall() {
		return recall;
	}

	public void setRecall(double recall) {
		this.recall = recall;
	}

	public double getF_measure() {
		return f_measure;
	}

	public void setF_measure(double f_measure) {
		this.f_measure = f_measure;
	}

	public int getTp() {
		return tp;
	}

	public void setTp(int tp) {
		this.tp = tp;
	}

	public int getFp() {
		return fp;
	}

	public void setFp(int fp) {
		this.fp = fp;
	}

	public int getFn() {
		return fn;
	}

	public void setFn(int fn) {
		this.fn = fn;
	}
	
}
